// pages/search/search.js
const App = getApp()
const httpRequest=require('../../utils/httpRequest.js')

Page({
  data: {
    searchkey:'',
    searchlist:[],
    Token:''
  },

  onLoad: function(options) {
    const userToken = wx.getStorageSync('userToken'); 
    this.setData({
      Token:userToken
    });
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('acceptDataFromHomePage2', (data) => {
      this.setData({
        searchkey: data.data
      });
      const keyword=this.data.searchkey;
      //获取搜索到的电影信息
      httpRequest.Request('Post',App.globalData.backend_add+'api/getsearchMovie?keyword='+keyword,{},{'Authorization': this.data.Token ,'content-type': 'application/json'},'searchlist',null,this)
    });
  },
  //跳转到详情页
  onHandleto(e) {
    const id = e.currentTarget.dataset.id;
    const movieData = this.data.searchlist[id];
    const movieid=this.data.searchlist[id].id;
    wx.navigateTo({
      url: '/pages/details/details',
      success: function (res) {
        const eventChannel = res.eventChannel;
        eventChannel.emit('acceptDataFromHomePage', {data: movieData}),
        eventChannel.emit('acceptDataFromHomePage1', {data: movieid})
      },
    });
  },
})